/**
 * @Author:  renyc
 * @Date:  2022年12月20日16:55:54
 */
import * as Cesium from "cesium/Cesium";
import LayerType from "../../layer/LayerType";
import Overlay from "../Overlay";

/**
 * @class PrimitiveOverlay
 * 
 * @description Cesium.Primitive类型的Overlay
 * 
 */
class PrimitiveOverlay extends Overlay{
    constructor(){
        super();
        this._delegate = undefined;
    }

    /**
     * 将Layer挂载到Viewer上(内部方法)
     * @protected
     * @Override
     */
    _attach(){
        if(!this._delegate){
            return false;
        }
        if(this._layer.type!=LayerType.PRIMITIVE){
             return false;
        }

        if(!this._layer._source){
            return false;
        }

        if(!this._layer._source._delegate){
            return false;
        }
        let source = this._layer._source;
        let primitives = source._delegate;
        if(!primitives){
            return false;
        }

        if(this._delegate){
            primitives.add(this._delegate);
        }

        return true;
     }

     /**
      * 将Layer从Viewer上卸载(内部方法)
      * @protected
      * @Override
      */
     _detach(){
        if(this._layer._source){
            let primitiveCollection = this._layer._source._delegate;        
            if(!primitiveCollection){
                return;
            }
            if(this._delegate){
                primitiveCollection.remove(this._delegate);
            }
        }
        
    }
}

export default PrimitiveOverlay
